
import javax.servlet.*;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
//@WebServlet("/MyServlet")
public class MyServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        response.setHeader("Content-Type", "text/html;charset=UTF-8");

        //设置用户名和密码
        String myUser = "admin";
        String myPwd = "123456";
        if (username.equals(myUser) && password.equals(myPwd)) {

            String html = "<h1 style='color:red;'>" + username + "用户成功登录</h>";
            response.getWriter().print(html);
//            response.sendRedirect(request.getContextPath() + "/Success.html");
        } else {
            String s = username + "用户名或密码错误，请重新输入";
            response.getWriter().write(s);
        }

    }

}
